/*
 * JBoss, Home of Professional Open Source
 *
 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
 * by the @author tags. See the COPYRIGHT.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.netty.handler.codec.bayeux;

/**
 * A Bayeux server MUST respond to a handshake request with a handshake response
 * message in the body content of the response. For cross domain connections
 * that have the 'jsonp' parameter set, the message body may be encapsulated in
 * a jsonp callback method.
 *
 * Successful handshake response
 *
 * A successful handshake responses MUST contain the message fields:
 *   channel
 *      value "/meta/handshake"
 *   version
 *   supportedConnectionTypes
 *     The connection types supported by the server for the purposes of the
 *     connection being negotiated. This list MAY be a subset of the connection
 *     types actually supported if the server wishes to negotiate a specific
 *     connection type. This list MUST contain at list one element in common
 *     with the supportedConnectionType provided in the handshake request. If
 *     there are no connectionTypes in common, the handshake response MUST be
 *     unsuccessful.
 *   clientId
 *     A newly generated unique clientId.
 *   successful
 *     value true
 *
 * A successful handshake response MAY contain the message fields:
 *   minimumVersion
 *   advice
 *   ext
 *   id
 *     same value as request message id
 *   authSuccessful
 *     Value true, this field may be included to support prototype client
 *     implementations that required the authSuccessful field
 *
 * An example successful handshake response is:
 * [
 *   {
 *     "channel": "/meta/handshake",
 *     "version": "1.0",
 *     "minimumVersion": "1.0beta",
 *     "supportedConnectionTypes": ["long-polling","callback-polling"],
 *     "clientId": "Un1q31d3nt1f13r",
 *     "successful": true,
 *     "authSuccessful": true,
 *     "advice": { "reconnect": "retry" }
 *   }
 * ]
 *
 * Unsuccessful handshake response
 *
 * An unsuccessful handshake response MUST contain the message fields:
 *   channel
 *     value "/meta/handshake"
 *   successful
 *     value false
 *   error
 *     a string with the description of the reason for the failure.
 * 
 * An unsuccessful handshake response MAY contain the message fields:
 *   supportedConnectionTypes
 *     The connection types supported by the server for the purposes of the
 *     connection being negotiated. This list MAY be a subset of the connection
 *     types actually supported if the server wishes to negotiate a specific
 *     connection type.
 *   advice
 *   version
 *   minimumVersion
 *   ext
 *   id
 *     same value as request message id
 *
 * An example unsuccessful handshake response is:
 * [
 *   {
 *      "channel": "/meta/handshake",
 *      "version": "1.0",
 *      "minimumVersion": "1.0beta",
 *      "supportedConnectionTypes": ["long-polling","callback-polling"],
 *      "successful": false,
 *      "error": "Authentication failed",
 *      "advice": { "reconnect": "none" }
 *    }
 * ]
 *
 * For complex connection negotiations, multiple handshake messages may be
 * exchanged between the Bayeux client and server. The handshake response will
 * set the "successful" field to false until the handshake processs is complete.
 * The advice and ext fields may be used to communicate additional information
 * needed to complete the handshake process. An unsuccessful handshake response
 * with reconnect advice of "handshake" is used to continue the connection
 * negotiation. An unsuccessful handshake response with reconnect advice of
 * "none" is used to terminate connection negotiations.
 * 
 * @author daijun
 */
public class HandshakeResponse extends BayeuxMessage {
    //required for handshake sucessfully and unsucessfully both
    //private String channel = "/meta/handshake";
    //private Boolean successful;

    //optional for handshake sucessfully and unsucessfully both
    //private String minimumVersion;
    //private BayeuxAdvice advice;
    //private BayeuxExt ext;
    //private String id;
    //required for handshake sucessfully, optional for handshake unsucessfully
    //private String version;
    //private String[] supportedConnectionTypes;
    //private String clientId;
    //only optional for handshake sucessfully
    //private boolean authSuccessful;
    //only required for handshake unsucessfully
    //private String error;
    public HandshakeResponse(HandshakeRequest handshakeRequest) {
        this.channel="/meta/handshake";
        this.id = handshakeRequest.getId();
    }

    @Override
    public boolean isValid() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
